package com.gitee.wsl.compose.modifier.draw

import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathEffect
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.gitee.wsl.common.ui.ext.drawScope.drawBottomSeparator
import com.gitee.wsl.common.ui.ext.drawScope.drawLeftSeparator
import com.gitee.wsl.common.ui.ext.drawScope.drawRightSeparator
import com.gitee.wsl.common.ui.ext.drawScope.drawTopSeparator
import com.gitee.wsl.compose.modifier.ModifierDrawScope


internal fun Modifier.topSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
) = drawBehind {
    drawTopSeparator(color, insetStart, insetEnd, if (strokeWidth == 0.dp) Stroke.HairlineWidth else strokeWidth.toPx(), pathEffect)
}

internal fun Modifier.rightSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
) = drawBehind {
    drawRightSeparator(color, insetStart, insetEnd, if (strokeWidth == 0.dp) Stroke.HairlineWidth else strokeWidth.toPx(), pathEffect)
}

internal fun Modifier.bottomSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
) = drawBehind {
    drawBottomSeparator(color, insetStart, insetEnd, if (strokeWidth == 0.dp) Stroke.HairlineWidth else strokeWidth.toPx(), pathEffect)
}

internal fun Modifier.leftSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
) = drawBehind {
    drawLeftSeparator(color, insetStart, insetEnd, if (strokeWidth == 0.dp) Stroke.HairlineWidth else strokeWidth.toPx(), pathEffect)
}

fun ModifierDrawScope.leftSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
){
    modifier = modifier.leftSeparator(color, insetStart, insetEnd, strokeWidth, pathEffect)
}

fun ModifierDrawScope.bottomSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
){
    modifier = modifier.bottomSeparator(color, insetStart, insetEnd, strokeWidth, pathEffect)
}

fun ModifierDrawScope.rightSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
){
    modifier = modifier.rightSeparator(color, insetStart, insetEnd, strokeWidth, pathEffect)
}

fun ModifierDrawScope.topSeparator(
    color: Color,
    insetStart: Dp = 0.dp,
    insetEnd: Dp = 0.dp,
    strokeWidth: Dp = 0.dp,
    pathEffect: PathEffect? = null
){
    modifier = modifier.topSeparator(color, insetStart, insetEnd, strokeWidth, pathEffect)
}